package com.haier.uos.weather.collection.job;

import com.haier.uos.weather.collection.client.ApiClient;
import com.haier.uos.weather.collection.service.IWeatherDataCollectionService;
import com.haier.uos.weather.collection.vo.City;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

public class WeatherDataCollectionJob extends QuartzJobBean {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private IWeatherDataCollectionService collectionService;
    @Autowired
    private ApiClient apiClient;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("start weather data collection job");
        List<City> cities  = apiClient.getAllCity();
        for (City c : cities) {
            collectionService.collectionWeatherDataByCityId(c.getCityId());
        }
        logger.info("end weather data collection job");
    }
}
